package me.chenqiang.tre.rule;

import java.math.BigDecimal;

/**
 * 表示匹配到规则时操作参数的类
 */
public class Action {
	
	protected boolean transactionAccepted;
	protected BigDecimal additionalChargeRate;
	
	public Action(boolean transactionAccepted, BigDecimal additionalChargeRate) {
		super();
		this.transactionAccepted = transactionAccepted;
		this.additionalChargeRate = additionalChargeRate;
		if(this.transactionAccepted && this.additionalChargeRate == null) {
			throw new IllegalArgumentException("加收费率为null");
		}
	}
	
	/**
	 * 是否允许交易
	 * @return
	 */
	public boolean isTransactionAccepted() {
		return transactionAccepted;
	}
	
	/**
	 * 加收或折扣费率
	 * @return
	 */
	public BigDecimal getAdditionalChargeRate() {
		return additionalChargeRate;
	}	
	
	public static final Action NORMAL = new Action(true, BigDecimal.valueOf(0, 0));
	public static final Action REJECT = new Action(false, null);
	
	@Override
	public String toString() {
		if(this.transactionAccepted) {
			return String.format("可以消费（费率%s％）", BigDecimal.valueOf(100, 0).multiply(this.additionalChargeRate).setScale(2).toPlainString());
		}
		else {
			return "不可消费";
		}
	}

}
